home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug191 / soundout.c < prev    next >
Text File  |  1986-05-25  |  2KB  |  80 lines

  1.  
  2. /*  SOUNDOUT.C                          Last update: 26 Feb 86  */
  3.  
  4. /* ------------------------------------------------------------ */
  5. /*      This is a portion of the SOUND EFFECTS LIBRARY.         */
  6. /*                                                              */
  7. /*      Copyright (C) 1986 by Paul Canniff.                     */
  8. /*      All rights reserved.                                    */
  9. /*                                                              */
  10. /*      This library has been placed into the public domain     */
  11. /*      by the author.  Use is granted for non-commercial       */
  12. /*      pusposes, or as an IMBEDDED PORTION of a commercial     */
  13. /*      product.                                                */
  14. /*                                                              */
  15. /*      Paul Canniff                                            */
  16. /*      PO Box 1056                                             */
  17. /*      Marlton, NJ 08053                                       */
  18. /*                                                              */
  19. /*      CompuServe ID: 73047,3715                               */
  20. /*                                                              */
  21. /* ------------------------------------------------------------ */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include "sound.h"
  26.  
  27. struct raw_sound soundbuff[SND_BUFFSIZE];
  28. unsigned sb_inptr = 0, sb_outptr = 0;
  29.  
  30. static unsigned tick_counter = 0;
  31.  
  32.  
  33. void sound_out()
  34. {
  35.     unsigned c;
  36.  
  37.     while (tick_counter-- == 0)
  38.     {
  39.         if (sb_inptr == sb_outptr)
  40.         {
  41.             tick_counter = 0;
  42.             spkr_off();
  43.             return;
  44.         }
  45.         else
  46.         {
  47.             sb_outptr = (sb_outptr + 1) % SND_BUFFSIZE;
  48.  
  49.             tick_counter = soundbuff[sb_outptr].ticks;
  50.             if ((c = soundbuff[sb_outptr].count) == 0)
  51.                 spkr_off();
  52.             else
  53.             {
  54.                 spkr_cntr(c);
  55.                 spkr_on();
  56.             }
  57.         }
  58.     }
  59. }
  60.  
  61.  
  62. void quiet()
  63. {
  64.     sb_inptr = sb_outptr = 0;
  65.     tick_counter = 0;
  66.     spkr_off();
  67. }
  68.  
  69.  
  70. void sound_bchk(used,remaining)
  71. int *used, *remaining;
  72. {
  73.     if (sb_inptr >= sb_outptr)
  74.         *used = sb_inptr - sb_outptr;
  75.     else
  76.         *used = sb_inptr + (SND_BUFFSIZE - sb_outptr);
  77.  
  78.     *remaining = SND_BUFFSIZE - *used;
  79. }
  80.